<?php
class User extends Model
{
	
	/**
	 * @return User
	 */
	public static function login($email, $password)
	{
		$oInstance = User::getSingle(array('email' => $email, 'password' => sha1(md5($password .'eerstesalt') .'tweedesalt')));
		
		if($oInstance instanceof self)
		{
			$_SESSION['userloggedin'] = $oInstance;
			return $oInstance;	
		}		
		return false;
	}
	
	/**
	 * @return User
	 */
	public static function getLoggedIn()
	{
		if($_SESSION['userloggedin'] instanceof self)
		{
			return $_SESSION['userloggedin'];
		}
		return false;
	}
	/**
	 * @return boolean
	 */
	public static function logout()
	{
		if($_SESSION['userloggedin'] instanceof self)
		{
			$_SESSION['userloggedin'] = null;
			return true;
		}
		return false;
	}
	
	public function getFullName()
	{
		return $this->firstname . ' ' . $this->lastname;
	}
	
	public function getListName()
	{
		if(self::getLoggedIn())
		{
			return 'jou';
		}
		return $this->getFullName();
	}
	/**
	 * 
	 * @param array $where
	 * @param string $orderBy
	 * @param string $dir
	 * @param int $limit
	 * @return array
	 */
	public static function getAll($where = array(), $orderBy = null, $dir = 'ASC', $limit = 0)
	{
		return self::getAllModels(get_class(), $where, $orderBy, $dir, $limit);
	}
}